package com.study.d012Components.dialog;

import java.util.Optional;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;

/** Alert弹出框
*@description
*@author xtayhame
*date 2020年3月14日
*version
*since v1.0
*/
public class AlertMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	public void start(javafx.stage.Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();

		Button button  = new Button("弹窗");

		anchorPane.getChildren().add(button);
		AnchorPane.setTopAnchor(button, 30.0);
		AnchorPane.setLeftAnchor(button, 30.0);

		stage.setScene(new Scene(anchorPane,400,300));
		stage.show();

		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				//信息确认框
				Alert alert = new Alert(AlertType.INFORMATION);

				//添加按钮
				alert.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);

				Button ok=(Button)alert.getDialogPane().lookupButton(ButtonType.OK);

				alert.show();

				ok.setOnAction(new EventHandler<ActionEvent>() {
					@Override
					public void handle(ActionEvent event) {
						System.out.println("Ok");
					}
				});

			}

		});

	}
}
